package com.bwie.home.backstage.controller;

import com.bwie.home.backstage.util.RandomCode;
import com.bwie.home.common.utils.HttpUtils;
import org.apache.http.HttpResponse;

import java.util.HashMap;
import java.util.Map;

public class Phone {


    /**
     *   发送验证码
     */

    public static String Phone(String phone) {

        String code = RandomCode.genCode();
        String host = "https://jnlzsms.market.alicloudapi.com";
        String path = "/lundroid/smsSend";
        String method = "GET";
        String appcode = "ee5993fb949c43bea0e67dff6edad408";
        Map<String, String> headers = new HashMap<>();
        //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
        headers.put("Authorization", "APPCODE " + appcode);
        Map<String, String> querys = new HashMap<>();
        querys.put("mobile", phone);
        querys.put("param", code);
        querys.put("templateId", "SMS_75800186");
        System.out.println(code);
        try {
            /*
              重要提示如下:
              HttpUtils请从
              https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
              下载

              相应的依赖请参照
              https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
             */
            HttpResponse response = HttpUtils.doGet(host, path, method, headers, querys);
            System.out.println(response.toString());
            //获取response的body
            //System.out.println(EntityUtils.toString(response.getEntity()));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return code;
    }

}
